<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 系统管理 <span class="c-gray en">&gt;</span> 角色管理<span class="c-gray en">&gt;</span> 设置角色菜单</nav>
	<div id="sectionContent" class="Hui-article">
		<article class="page-container">
			<div class="form form-horizontal" id="form-admin-add">
				<div class="row cl">
					<label class="form-label col-xs-4 col-sm-3">&nbsp;</label>
					<div class="formControls col-xs-8 col-sm-9">
						<input type="hidden" id="menuIds"/>
	          <ul id="systemMenus" class="ztree"></ul>
					</div>
				</div>
				<div class="row cl">
					<div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
						<input class="btn btn-primary" type="button" v-on:click="saveData()" value="&nbsp;&nbsp;提交&nbsp;&nbsp;" style="margin-right:30px;">
						<input class="btn" type="button" onclick="javascript:history.go(-1)" value="&nbsp;&nbsp;取消&nbsp;&nbsp;">
					</div>
				</div>
			</div>
		</article>
	</div>
<script>
    new Vue({
        el:'#sectionContent',
        http: authorization(),
        created:function(){
            this.$http.get('/restful/base/v1.0/auth/user/role/menus?roleId='+getQueryString('id')).then((response) => {
                var setting = {
                    check: {
                        enable: true
                    },
                    data: {
                        simpleData: {
                            enable: true,
                            pIdKey: "pid"
                        }
                    },
                    callback:{
                        onCheck:this.onCheck
                    }
                };
                $.fn.zTree.init($("#systemMenus"), setting, responseObj(response).data);
            }).catch(function(response) {
                alert(errorMsg(response));
            });
        },
        methods:{
            onCheck:function(e,treeId,treeNode){
                var treeObj=$.fn.zTree.getZTreeObj("systemMenus"),nodes=treeObj.getCheckedNodes(true),v="";
                for(var i=0;i<nodes.length;i++){
                    v+=nodes[i].id + ",";
                }
                $('#menuIds').val(v);
            },
            backToList:function(){
                window.parent.location.href="#!view/system/role/role-list.html?"+Math.random();
            },
            saveData:function(){
                var uri = "/restful/base/v1.0/auth/setting/user/role/menus?roleId="+getQueryString('id'),menus = $('#menuIds').val();
                if(menus != null && menus.length >0){
                    uri += "&menus="+menus.substr(0,menus.length-1);
                }
                this.$http.post(uri).then((response) => {
                    this.backToList();
                }).catch(function(response) {
                    alert(errorMsg(response));
                });
            }
        }
    });
</script>
